package com.zjw.mybatis.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zjw.mybatis.model.User;

public interface IUserDao {
	public static final String SELECT_SQL_FIELDS = " id,username,nickname,password,age,create_time as createTime ";
	public static final String TABLE_NAME = " t_user ";

	@Insert("INSERT INTO  " + TABLE_NAME
			+ "(username,nickname,password,age,create_time)"
			+ "values(#{username},#{nickname},#{password},#{age},now())")
	public void save(User user);

	@Update("UPDATE " + TABLE_NAME
			+ "SET "
			+ "username=#{username},nickname=#{nickname},password=#{password},age=#{age} "
			+ "WHERE id = #{id}")
	public void update(User user);
	
	@Delete("DELETE FROM "+TABLE_NAME+" WHERE id = #{id}")
	public void delete(long id);
	
	@Select("SELECT " + SELECT_SQL_FIELDS + "FROM "+TABLE_NAME+" WHERE id = #{id}")
	public User load(long id);
	
	@Select("SELECT " + SELECT_SQL_FIELDS + " FROM " + TABLE_NAME)
	public List<User> list();
}
